package com.cmc.cloud.cmclink.doc.api.document.req.so;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.hibernate.validator.constraints.Length;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

/**
 * 特种货审批dg Base VO，提供给添加、修改、详细的子 VO 使用
 * 如果子 VO 存在差异的字段，请不要添加到这里，影响 Swagger 文档生成
 *
 * @author codegen
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class SpecialCargoDgBaseVO {

    private Long id;

    @Schema(description = "DG临时标识")
    private Long dgLabel;

    @Schema(description = "特种货申请id", requiredMode = Schema.RequiredMode.REQUIRED, example = "32189")
    private Long applyId;

    @Schema(description = "联合国危险品编号", requiredMode = Schema.RequiredMode.REQUIRED)
    @Length(max = 4, message = "联合国危险品编号支持最大长度{max}")
    private String unNo;

    @Schema(description = "国际海事局危险品分类", requiredMode = Schema.RequiredMode.REQUIRED)
    @Length(max = 4, message = "国际海事局危险品分类支持最大长度{max}")
    private String imoClass;

    @Schema(description = "正确运输名称", requiredMode = Schema.RequiredMode.REQUIRED)
    @Length(max = 256, message = "正确运输名称支持最大长度{max}")
    private String psn;

    @Schema(description = "包装组别", requiredMode = Schema.RequiredMode.REQUIRED)
    @Length(max = 50, message = "包装组别支持最大长度{max}")
    private String packingGroup;

    @Schema(description = "技术名称", example = "赵六")
    @Length(max = 500, message = "技术名称支持最大长度{max}")
    private String technicalName;

    @Schema(description = "副危险")
    @Length(max = 50, message = "副危险支持最大长度{max}")
    private String subsidiaryRisk;

    @Schema(description = "是否数量限制", requiredMode = Schema.RequiredMode.REQUIRED)
    private Boolean limitedQty;

    @Schema(description = "海污", requiredMode = Schema.RequiredMode.REQUIRED)
    private Boolean marinePollutant;

    @Schema(description = "货物状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
    @Length(max = 20, message = "货物状态支持最大长度{max}")
    private String cargoStatus;

    @Schema(description = "应急反应措施编号")
    @Length(max = 64, message = "应急反应措施编号支持最大长度{max}")
    private String emsNo;

    @Schema(description = "危险品货物毛重", requiredMode = Schema.RequiredMode.REQUIRED)
    private BigDecimal dgGrossWgt;

    @Schema(description = "危险品货物净重", requiredMode = Schema.RequiredMode.REQUIRED)
    private BigDecimal dgNetWgt;

    @Schema(description = "医疗急救指南编号")
    @Length(max = 20, message = "医疗急救指南编号支持最大长度{max}")
    private String mfagNo;

    @Schema(description = "紧急应变指南编号")
    @Length(max = 20, message = "紧急应变指南编号支持最大长度{max}")
    private String erg;

    @Schema(description = "隔离组")
    @Length(max = 100, message = "隔离组支持最大长度{max}")
    private String segregationGroup;

    @Schema(description = "闪点")
    private BigDecimal flashPoint;

    @Schema(description = "电池状态", example = "2")
    @Length(max = 64, message = "电池状态支持最大长度{max}")
    private String batteryStatus;

    @Schema(description = "爆炸物含量")
    private BigDecimal netExplosiveWgt;

    @Schema(description = "紧急联系人名称", requiredMode = Schema.RequiredMode.REQUIRED)
    @Length(max = 50, message = "紧急联系人名称支持最大长度{max}")
    private String emergencyContactName;

    @Schema(description = "紧急联系人地址", requiredMode = Schema.RequiredMode.REQUIRED)
    @Length(max = 50, message = "紧急联系人地址支持最大长度{max}")
    private String emergencyContactAddress;

    @Schema(description = "紧急联系人电话", requiredMode = Schema.RequiredMode.REQUIRED)
    @Length(max = 50, message = "紧急联系人电话支持最大长度{max}")
    private String emergencyContactMobile;

    @Schema(description = "紧急联系人邮箱")
    @Length(max = 50, message = "紧急联系人邮箱支持最大长度{max}")
    private String emergencyContactEmail;

    @Schema(description = "紧急联系人传真")
    @Length(max = 50, message = "紧急联系人传真支持最大长度{max}")
    private String emergencyContactFax;

    @Schema(description = "dg内包装信息")
    private List<PackingCreateOrUpdateVO> innerDgPacking;

    @Schema(description = "dg外包装信息")
    private List<PackingCreateOrUpdateVO> outerDgPacking;

    @Schema(description = "dgCAS信息")
    private List<CasCreateOrUpdateVO> dgCasInfo;

    public void validate() {
        List<String> errors = new ArrayList<>();
        if (StringUtils.isEmpty(unNo)) {
            errors.add("联合国危险品编号不能为空");
        }
        if (StringUtils.isEmpty(imoClass)) {
            errors.add("国际海事局危险品分类不能为空");
        }
        if (StringUtils.isEmpty(psn)) {
            errors.add("正确运输名称不能为空");
        }
        if (StringUtils.isEmpty(packingGroup)) {
            errors.add("包装组别不能为空");
        }
        if (null == marinePollutant) {
            errors.add("海污不能为空");
        }
        if (StringUtils.isEmpty(cargoStatus)) {
            errors.add("货物状态不能为空");
        }
        if (null == limitedQty) {
            errors.add("是否数量限制不能为空");
        }
        if (null == dgNetWgt) {
            errors.add("危险品货物毛重不能为空");
        }
        if (StringUtils.isEmpty(emergencyContactName)) {
            errors.add("紧急联系人不能为空");
        }
        if (StringUtils.isEmpty(emergencyContactAddress)) {
            errors.add("紧急联系人地址不能为空");
        }
        if (StringUtils.isEmpty(emergencyContactMobile)) {
            errors.add("紧急联系人电话不能为空");
        }
        if (!errors.isEmpty()) {
            String errorInfo = String.join(",", errors);
        }
    }

}
